package com.zlyx.easy.core.app;

public final class AppUtils {

	private static Class<?> mainClass;

	public static Class<?> getMainClass() {
		if (mainClass == null) {
			try {
				StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
				for (StackTraceElement stackTraceElement : stackTrace) {
					if ("main".equals(stackTraceElement.getMethodName())) {
						mainClass = Class.forName(stackTraceElement.getClassName());
						return mainClass;
					}
				}
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		return mainClass;
	}

	public static String getMainPackagePath() {
		return getMainClass().getPackage().getName();
	}

}
